package logic

import (
	"context"
	"doctor-medicine-system/goods/goods"

	"doctor-medicine-system/api/internal/svc"
	"doctor-medicine-system/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateApiLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateApiLogic {
	return &UpdateApiLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateApiLogic) UpdateApi(req *types.UpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.GoodsRpc.Update(l.ctx, &goods.UpdateRequest{
		Name:   req.Name,
		Size:   req.Size,
		Form:   req.Form,
		Eat:    req.Eat,
		Use:    req.Use,
		Moment: req.Moment,
		GoodId: req.GoodId,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "修改成功",
		Data:    update,
		Code:    200,
	}, nil
}
